#ifndef LISTVIEW_H
#define LISTVIEW_H

#include <QStyledItemDelegate>
#include <QList>
#include <QAbstractListModel>
#include <QPainter>
#include <QPalette>
#include <QPixmap>
#include <QListView>
#include <QScroller>

#include <QDebug>
#include <QMouseEvent>


struct KeyInfo
{
    QString data;
    QString icon;
};

class ListView : public QListView
{
    Q_OBJECT
public:
    ListView(QWidget *parent = nullptr);
};

class ListModel :public QAbstractListModel
{
    Q_OBJECT
public:
    enum
    {
        DataRole = Qt::UserRole,
        IconRole,
    };
    ListModel();
    ~ListModel(){}
    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    QVariant data(const QModelIndex & index, int role) const;
    bool setData(const QModelIndex &index, const QVariant &value, int role  = Qt::EditRole );

    void addList(const QList<KeyInfo>& list);
    void addData(QString data, QString icon);
    void clear();

protected:
    QList<KeyInfo> list;
};

class Delegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    Delegate(QObject* parent = nullptr);
    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
    QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;

    bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)override;

    QPoint              pressPos;
    bool                isMove = false;
    bool                isPress = true;
signals:
    void itemClicked(QString);
};

#endif // LISTVIEW_H
